import { GatherInterfaceBtnService } from './interfaceBtn.service';
import { Body, Controller, Post, Get } from '@nestjs/common';
import { ApiOkResponse, ApiOperation, ApiSecurity, ApiTags } from '@nestjs/swagger';
import { ADMIN_PREFIX } from '../../admin.constants';
import { AdminUser } from '../../core/decorators/admin-user.decorator';

@ApiSecurity(ADMIN_PREFIX)
@ApiTags('调机按钮配置管理模块')
@Controller('interfaceBtn')
export class GatherInterfaceBtnController {
  constructor(private gatherInterfaceBtnService: GatherInterfaceBtnService) {}

  @ApiOperation({ summary: '获取调机按钮配置列表' })
  @ApiOkResponse()
  @Get('list')
  async list() {
    return await this.gatherInterfaceBtnService.list();
  }

  @ApiOperation({ summary: '分页获取获取调机按钮配置列表' })
  @ApiOkResponse()
  @Post('page')
  async page(@Body() dto) {
    const [list, total] = await this.gatherInterfaceBtnService.page(dto);

    return {
      list,
      pagination: {
        total,
        pageNum: dto.pageNum,
        pageSize: dto.pageSize,
      },
    };
  }

  @ApiOperation({ summary: '添加调机按钮配置' })
  @ApiOkResponse()
  @Post('add')
  async add(@Body() dto, @AdminUser() user) {
    await this.gatherInterfaceBtnService.isExistKey(dto);

    await this.gatherInterfaceBtnService.add(dto, user);
  }

  @ApiOperation({ summary: '修改调机按钮配置' })
  @ApiOkResponse()
  @Post('update')
  async update(@Body() dto, @AdminUser() user) {
    await this.gatherInterfaceBtnService.update(dto, user);
  }

  @ApiOperation({ summary: '删除调机按钮配置' })
  @ApiOkResponse()
  @Post('delete')
  async delete(@Body() dto) {
    await this.gatherInterfaceBtnService.delete(dto);
  }
}
